package com.zk.shop.servlet.user;

import com.zk.shop.entity.User;
import com.zk.shop.service.Impl.UserServiceImpl;
import com.zk.shop.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName CheckNameServlet
 * @Description TODO
 * @Author 来永刚
 * @Date 2019/10/8 0008下午 7:27
 * @Version 1.0
 **/
@WebServlet("/user/CheckNameServlet")
public class CheckNameServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("username");
        UserService userService = new UserServiceImpl();
        User user = userService.checkName(name);
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        if (user != null) {
            out.print("true");
        } else {
            out.print("false");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
